package com.micro.frog.rbac.controller;

import com.micro.frog.common.base.Result;
import com.micro.frog.rbac.entity.DictClassDO;
import com.micro.frog.rbac.service.DictClassService;
import lombok.AllArgsConstructor;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * @author :  ljh
 * @date : 2018/4/11
 **/
@RestController
@AllArgsConstructor
@RequestMapping("/rbac/dict/class")
public class DictClassController {

    private final DictClassService dictClassService;

    /**
     * 字典类型接口类
     */
    @GetMapping(value = "/list")
    public Result list() {
        return Result.success(dictClassService.list());
    }

    @PostMapping("/add")
    public Result add(DictClassDO req) {
        boolean flag = dictClassService.save(req);
        return flag ? Result.success("添加成功") : Result.error("添加失败");
    }

    @PostMapping("/delete")
    public Result delete(Long id) {
        boolean flag = dictClassService.delete(id);
        return flag ? Result.success("删除成功") : Result.error("删除失败");
    }

    @PostMapping("/update")
    public Result update(DictClassDO req) {
        boolean flag = dictClassService.updateById(req);
        return flag ? Result.success("更新成功") : Result.error("更新失败");
    }

}
